package com.neusoft.hifly.dev;

import com.neusoft.hifly.commons.database.SQLUtil;
import com.neusoft.hifly.commons.file.FileUtil;
import com.neusoft.hifly.dvpt.domain.Contact;
import com.neusoft.hifly.dvpt.domain.DataBaseInfo;
import com.neusoft.hifly.dvpt.domain.PathInfo;
import com.neusoft.hifly.dvpt.util.EngineerUtil;

/**
 * Title: 核心类库
 * <p>
 * Description: 逆向工程，将数据库中的表生成java对象
 * <p>
 * Copyright: 2013
 * <p>
 * Company: 东软汉枫
 *
 * @author lihui
 * @version 1.0.0
 */
public final class ReverseEngineer {

	/**
	 * 测试MySQL数据库
	 * <p>
	 * 创建表规则：
	 * <p>
	 * 2 表名：必须有前缀，否则将读取系统其它无用表。例如：s_admin
	 * <p>
	 * 列：主键必须以表名(去掉前缀)+“_id”，逻辑ID必须以表名(去掉前缀)+“_logic_id”。例如：admin_id,admin_logic_id
	 * <p>
	 * 列名：词组直接用“_”分隔。例如:admin_name
	 *
	 * @param args
	 *            参数
	 */
	public static void main(final String[] args) {
		final Contact contact = new Contact();
		contact.setPackageName("com.neusoft.hifly.card");
		contact.setAuthor("wg");
		contact.setVersion("1.0.0");
		contact.setName("终端管理服务");
		contact.setApp("终端");
		contact.setCopyright("2018");
		contact.setCompany("东软汉枫");

		final DataBaseInfo db = new DataBaseInfo();
		db.setDbType(SQLUtil.DB_MYSQL);
		db.setIp("db_service");
		db.setPort("3306");
		db.setCharacterEncoding("UTF-8");
		db.setSchema("ctcloud-service-tenant");
		db.setUser("kfb");
		db.setPassword("Product@7833");
		// { "sys_", "form_", "tenant_", "test_", "system_" }
		db.setBeforeName(new String[] { "system_" });
		db.setExecptName("_DEL");

		final PathInfo path = new PathInfo();
		path.setBasePath(FileUtil.getWebClassesPath().replace("target/test-classes/", "document"));
		// 单体模式
		path.setTempPath("/ReverseEngineerTemp/springboot-mybatis-micro");
		// saas模式
		//		path.setTempPath("/ReverseEngineerTemp/springboot-mybatis-micro-muti");
		path.setDelPath("/ReverseEngineerTemp/logicdel");
		path.setReversePath("/reverseCode");

		final EngineerUtil util = new EngineerUtil();
		for (final String beforeName : db.getBeforeName()) {
			util.engineer(path, db, contact, beforeName, false, true);
			//		renameTenantCode(beforeName);
		}
	}

}
